package com.scms.secondclass.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.scms.common.annotation.Log;
import com.scms.common.core.controller.BaseController;
import com.scms.common.core.domain.AjaxResult;
import com.scms.common.enums.BusinessType;
import com.scms.secondclass.domain.ActivityCategory;
import com.scms.secondclass.service.IActivityCategoryService;
import com.scms.common.utils.poi.ExcelUtil;
import com.scms.common.core.page.TableDataInfo;

/**
 * 活动分类Controller
 * 
 * @author thy
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/secondclass/category")
public class ActivityCategoryController extends BaseController
{
    @Autowired
    private IActivityCategoryService activityCategoryService;

    /**
     * 查询活动分类列表
     */
    @PreAuthorize("@ss.hasPermi('secondclass:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityCategory activityCategory)
    {
        startPage();
        List<ActivityCategory> list = activityCategoryService.selectActivityCategoryList(activityCategory);
        return getDataTable(list);
    }

    /**
     * 查询活动分类树形结构
     */
    @PreAuthorize("@ss.hasPermi('secondclass:category:list')")
    @GetMapping("/treeList")
    public AjaxResult treeList(ActivityCategory activityCategory)
    {
        List<ActivityCategory> list = activityCategoryService.selectActivityCategoryTreeList(activityCategory);
        return success(list);
    }

    /**
     * 获取活动分类下拉选项
     */
    @GetMapping("/options")
    public AjaxResult getOptions()
    {
        ActivityCategory query = new ActivityCategory();
        query.setStatus("0"); // 只查询正常状态的分类
        List<ActivityCategory> list = activityCategoryService.selectActivityCategoryTreeList(query);
        // 添加日志输出，便于调试
        System.out.println("返回的分类选项数据: " + list);
        return success(list);
    }

    /**
     * 导出活动分类列表
     */
    @PreAuthorize("@ss.hasPermi('secondclass:category:export')")
    @Log(title = "活动分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityCategory activityCategory)
    {
        List<ActivityCategory> list = activityCategoryService.selectActivityCategoryList(activityCategory);
        ExcelUtil<ActivityCategory> util = new ExcelUtil<ActivityCategory>(ActivityCategory.class);
        util.exportExcel(response, list, "活动分类数据");
    }

    /**
     * 获取活动分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('secondclass:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(activityCategoryService.selectActivityCategoryByCategoryId(categoryId));
    }

    /**
     * 新增活动分类
     */
    @PreAuthorize("@ss.hasPermi('secondclass:category:add')")
    @Log(title = "活动分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityCategory activityCategory)
    {
        return toAjax(activityCategoryService.insertActivityCategory(activityCategory));
    }

    /**
     * 修改活动分类
     */
    @PreAuthorize("@ss.hasPermi('secondclass:category:edit')")
    @Log(title = "活动分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityCategory activityCategory)
    {
        return toAjax(activityCategoryService.updateActivityCategory(activityCategory));
    }

    /**
     * 删除活动分类
     */
    @PreAuthorize("@ss.hasPermi('secondclass:category:remove')")
    @Log(title = "活动分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(activityCategoryService.deleteActivityCategoryByCategoryIds(categoryIds));
    }
}
